package org.jnativehook;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.event.EventListenerList;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyException;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseListener;
import org.jnativehook.mouse.NativeMouseMotionListener;

public class GlobalScreen
{
  private static final long serialVersionUID = 6504561173380322679L;
  private static GlobalScreen instance = new GlobalScreen();
  private EventListenerList eventListeners = new EventListenerList();

  private GlobalScreen()
  {
    registerHook();
  }

  protected void finalize()
    throws Throwable
  {
    try
    {
      unregisterHook();
    }
    catch (Exception localException)
    {
    }
    finally
    {
      super.finalize();
    }
  }

  public static synchronized GlobalScreen getInstance()
  {
    return instance;
  }

  public void addNativeKeyListener(NativeKeyListener paramNativeKeyListener)
  {
    if (paramNativeKeyListener != null)
      this.eventListeners.add(NativeKeyListener.class, paramNativeKeyListener);
  }

  public void removeNativeKeyListener(NativeKeyListener paramNativeKeyListener)
  {
    if (paramNativeKeyListener != null)
      this.eventListeners.remove(NativeKeyListener.class, paramNativeKeyListener);
  }

  public void addNativeMouseListener(NativeMouseListener paramNativeMouseListener)
  {
    this.eventListeners.add(NativeMouseListener.class, paramNativeMouseListener);
  }

  public void removeNativeMouseListener(NativeMouseListener paramNativeMouseListener)
  {
    this.eventListeners.remove(NativeMouseListener.class, paramNativeMouseListener);
  }

  public void addNativeMouseMotionListener(NativeMouseMotionListener paramNativeMouseMotionListener)
  {
    this.eventListeners.add(NativeMouseMotionListener.class, paramNativeMouseMotionListener);
  }

  public void removeNativeMouseMotionListener(NativeMouseMotionListener paramNativeMouseMotionListener)
  {
    this.eventListeners.remove(NativeMouseMotionListener.class, paramNativeMouseMotionListener);
  }

  public native long getAutoRepeatRate()
    throws NativeKeyException;

  public native long getAutoRepeatDelay()
    throws NativeKeyException;

  public final void dispatchEvent(NativeInputEvent paramNativeInputEvent)
  {
    if ((paramNativeInputEvent instanceof NativeKeyEvent))
      processKeyEvent((NativeKeyEvent)paramNativeInputEvent);
    else if ((paramNativeInputEvent instanceof NativeMouseEvent))
      processMouseEvent((NativeMouseEvent)paramNativeInputEvent);
  }

  protected void processKeyEvent(NativeKeyEvent paramNativeKeyEvent)
  {
    Object[] arrayOfObject = this.eventListeners.getListenerList();
    int i = paramNativeKeyEvent.getID();
    for (int j = 0; j < arrayOfObject.length; j += 2)
    {
      if (arrayOfObject[j] != NativeKeyListener.class)
        continue;
      switch (i)
      {
      case 2400:
        ((NativeKeyListener)arrayOfObject[(j + 1)]).keyPressed(paramNativeKeyEvent);
        break;
      case 2401:
        ((NativeKeyListener)arrayOfObject[(j + 1)]).keyReleased(paramNativeKeyEvent);
      }
    }
  }

  protected void processMouseEvent(NativeMouseEvent paramNativeMouseEvent)
  {
    Object[] arrayOfObject = this.eventListeners.getListenerList();
    int i = paramNativeMouseEvent.getID();
    for (int j = 0; j < arrayOfObject.length; j += 2)
      if (arrayOfObject[j] == NativeMouseListener.class)
      {
        switch (i)
        {
        case 2500:
          ((NativeMouseListener)arrayOfObject[(j + 1)]).mousePressed(paramNativeMouseEvent);
          break;
        case 2501:
          ((NativeMouseListener)arrayOfObject[(j + 1)]).mouseReleased(paramNativeMouseEvent);
        }
      }
      else
      {
        if (arrayOfObject[j] != NativeMouseMotionListener.class)
          continue;
        switch (i)
        {
        case 2502:
          ((NativeMouseMotionListener)arrayOfObject[(j + 1)]).mouseMoved(paramNativeMouseEvent);
        }
      }
  }

  protected static void registerHook()
  {
    try
    {
      System.loadLibrary("JNativeHook");
    }
    catch (UnsatisfiedLinkError localUnsatisfiedLinkError)
    {
      try
      {
        String str1 = "org/jnativehook/lib/" + NativeSystem.getFamily().toString().toLowerCase() + "/" + NativeSystem.getArchitecture().toString().toLowerCase() + "/";
        File localFile1 = new File(GlobalScreen.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsoluteFile();
        Object localObject1;
        Object localObject2;
        if (localFile1.isFile())
        {
          localObject1 = new ZipInputStream(new FileInputStream(localFile1));
          while ((localObject2 = ((ZipInputStream)localObject1).getNextEntry()) != null)
          {
            if ((((ZipEntry)localObject2).isDirectory()) || (!((ZipEntry)localObject2).getName().toLowerCase().startsWith(str1.toLowerCase())))
              continue;
            String str2 = ((ZipEntry)localObject2).getName().substring(((ZipEntry)localObject2).getName().lastIndexOf('/'));
            File localFile2 = new File(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator", File.separator) + str2);
            FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
            byte[] arrayOfByte = new byte[8192];
            int i = 0;
            while ((i = ((ZipInputStream)localObject1).read(arrayOfByte)) > 0)
              localFileOutputStream.write(arrayOfByte, 0, i);
            localFileOutputStream.close();
            localFile2.deleteOnExit();
            System.load(localFile2.getPath());
          }
          ((ZipInputStream)localObject1).close();
        }
        else if (localFile1.isDirectory())
        {
          localObject1 = new File(localFile1.getAbsoluteFile() + "/" + str1);
          if (((File)localObject1).isDirectory())
          {
            System.setProperty("java.library.path", System.getProperty("java.library.path", ".") + System.getProperty("path.separator", ":") + ((File)localObject1).getPath());
            localObject2 = ClassLoader.class.getDeclaredField("sys_paths");
            ((Field)localObject2).setAccessible(true);
            if (localObject2 != null)
              ((Field)localObject2).set(System.class.getClassLoader(), null);
            System.loadLibrary("JNativeHook");
          }
        }
      }
      catch (Exception localException)
      {
        throw new NativeHookException(localException.getMessage(), localException.getCause());
      }
    }
  }

  protected static void unregisterHook()
  {
  }
}

/* Location:           D:\Downloads\JNativeHook\jar\JNativeHook.jar
 * Qualified Name:     org.jnativehook.GlobalScreen
 * JD-Core Version:    0.6.0
 */